﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MadMediaManager.Core.DependencyInjectionSupport;
using MadMediaManager.WPFSupport;
using MadMediaManager.WPFSupport.Interfaces.ViewModels;
using MadMediaManager.WPFSupport.Interfaces.Views;
using Sanbox.ViewModels;

namespace Sanbox
{
    /// <summary>
    /// Interaction logic for ViewManagerTestWindow.xaml
    /// </summary>
    public partial class ViewManagerTestWindow : Window, IMainView, IContentRegionOwner
    {
        public ViewManagerTestWindow()
        {
            InitializeComponent();
        }

        public ViewManagerTestWindow(IViewModel viewModel)
        {
            ViewModel = viewModel;
        }

        public IViewModel ViewModel
        {
            get { return DataContext as IViewModel; }
            set { DataContext = value; }
        }

        public void AddView(INavigableView view)
        {
            this.mainContent.Children.Add((UIElement)view);
        }

        public void RemoveView(INavigableView view)
        {
            this.mainContent.Children.Remove(view as UIElement);
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        public void Dispose()
        {
            if (ViewModel != null)
            {
                ViewModel.Dispose();
                ViewModel = null;
            }
            Close();
        }
    }
}
